package com.atguigu.guli.service.vod.controller.admin;

import com.atguigu.guli.service.base.result.R;
import com.atguigu.guli.service.vod.service.MediaService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Api(tags = "阿里云视频点播")
 //跨域
@RestController
@RequestMapping("/admin/vod/media")
@Slf4j
public class AdminMediaController {
    @Autowired
    MediaService mediaService;
    //2、上传视频到vod：加密转码   返回视频的id
    //1、上传视频到vod：不加密    返回视频的id
    @PostMapping("upload") //上传时如果 encrypt =1 表示加密，其他不加密
    public R upload(MultipartFile file ,
                    @RequestParam(required = false, defaultValue = "1") Integer encrypt){
        String vid  = mediaService.upload(file, encrypt);
        return R.ok().setData("id" , vid);
    }

    //3、根据视频id 获取未加密视频的播放地址
    @GetMapping("getPlayUrl/{vid}")
    public R getPlayUrl(@PathVariable String vid){
       String playUrl = mediaService.getPlayUrl(vid);
       return R.ok().setData("playUrl" , playUrl);
    }
    //4、根据视频id 获取加密视频的播放凭证: 使用多
    @GetMapping("getPlayAuth/{vid}")
    public R getPlayAuth(@PathVariable String vid){
        String playAuth = mediaService.getPlayAuth(vid);
        return R.ok().setData("playAuth" , playAuth);
    }
}
